{include file="public/layout" /}
<body>
  <div class="layui-fluid" id="LAY-component-layer-list">
    <div class="layui-row">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="web-system">
            <div class="layui-tab layui-tab-card">
              {neq name='$Request.param.tabase' value='-1'}
              <ul class="layui-tab-title">
                  {eq name="'System@water'|is_check_access" value="1"}
                  <li><a href="{:url('System/water')}">水印配置</a></li>
                  {/eq}

                  {eq name="'System@thumb'|is_check_access" value="1"}
                  <li class="layui-this"><a href="{:url('System/thumb')}">缩略图配置</a></li>
                  {/eq}
              </ul>
              {/neq}
              <div class="layui-tab-content" style="padding:10px 0">
                <div class="layui-tab-item layui-show">
                  <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                      <div class="layui-card">
                        <div class="layui-card-body" pad15>
                          <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                              <label class="layui-form-label">缩略图功能</label>
                              <div class="layui-input-inline w70">
                                <input type="checkbox" lay-filter="thumb_open" lay-skin="switch" lay-text="开启|关闭" {if condition='isset($config.thumb_open) && $config.thumb_open eq 1'}checked{/if}>
                                <input type="hidden" name="thumb_open" value="{$config.thumb_open|default='0'}" />
                              </div>
                              <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                <div class="layui-form-mid layui-word-aux ey_helptips"></div>
                                <div class="layui-form-inline2 ey_helptips_txt">全站图片进行缩略图处理</div>
                              </div>
                            </div>
                            <div class="layui-form-item">
                              <label class="layui-form-label">生成方式</label>
                              <div class="layui-input-inline">
                                 <input type="radio" name="thumb_mode" value="1" title="拉伸" {if condition="isset($config.thumb_mode) AND $config.thumb_mode eq 1"}checked="checked"{/if}>
                                  <input type="radio" name="thumb_mode" value="2" title="留白" {if condition="!isset($config.thumb_mode) OR $config.thumb_mode eq 2"}checked="checked"{/if}>
                                  <input type="radio" name="thumb_mode" value="3" title="裁减" {if condition="isset($config.thumb_mode) AND $config.thumb_mode eq 3"}checked="checked"{/if}>
                              </div>
                            </div>
                            <div class="layui-form-item">
                              <label class="layui-form-label">缩略图大小</label>
                              <div class="layui-input-inline w70" style="margin-right: 0">
                                  <input style="width:50px;float: left" type="text" name="thumb_width" lay-verify="number" value="{$config.thumb_width}" class="layui-input"> <span style="float: left;line-height: 38px;margin:0 4px;">X</span>
                              </div>
                              <div class="layui-input-inline w240">
                                  <input style="width: 50px;float: left" type="text" name="thumb_height" lay-verify="number" value="{$config.thumb_height}" class="layui-input"> <span style="float: left;line-height: 38px;margin-left: 4px;">(宽 X 高) (像素)</span>
                              </div>
                            </div>
                            <div class="layui-form-item">
                              <label class="layui-form-label"></label>
                              <div class="layui-input-inline">
                                 <a href="javascript:void(0);" id="tag_call" data-field="thumb_open">缩略图标签高级调用？</a>
                              </div>
                            </div>
                            <div class="layui-form-item">
                              <div class="layui-input-block">
                                  <input type="hidden" name="tabase" value="{$Request.param.tabase}">
                                  <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
     </div>
  </div>

  <script>
  layui.config({
    base: '__SKIN__/' //静态资源所在路径
    ,version: '{$version}'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form'], function(){
    var $ = layui.$
    ,layer = layui.layer
    ,form = layui.form;

    setthumb('auto'); // 关闭状态下禁用表单录入
    function setthumb(obj){
        if ('auto' == obj) {
            $('input[name="thumb_mode"]').attr('disabled', true).next().addClass('layui-radio-disbaled layui-disabled');
            $('input[name="thumb_width"]').attr('disabled', true);
            $('input[name="thumb_height"]').attr('disabled', true);
            $('input[name="thumb_color"]').attr('disabled', true);
            var thumb_open = $('input[name=thumb_open]').val();
            if (1 == thumb_open) {
                $('input[name="thumb_mode"]').attr('disabled', false).next().removeClass('layui-radio-disbaled layui-disabled');
                $('input[name="thumb_width"]').attr('disabled', false);
                $('input[name="thumb_height"]').attr('disabled', false);
                $('input[name="thumb_color"]').attr('disabled', false);
            }
        } else {
            var thumb_open = $('input[name=thumb_open]').val();
            if (1 == thumb_open) {
                $('input[name="thumb_mode"]').attr('disabled', false).next().removeClass('layui-radio-disbaled layui-disabled');
                $('input[name="thumb_width"]').attr('disabled', false);
                $('input[name="thumb_height"]').attr('disabled', false);
                $('input[name="thumb_color"]').attr('disabled', false);
            } else {
                $('input[name="thumb_mode"]').attr('disabled', true).next().addClass('layui-radio-disbaled layui-disabled');
                $('input[name="thumb_width"]').attr('disabled', true);
                $('input[name="thumb_height"]').attr('disabled', true);
                $('input[name="thumb_color"]').attr('disabled', true);
            } 
        }
    }

    $('#tag_call').click(function(){
        var name = $(this).data('field');
        $.ajax({
            type: "POST",
            url: "{:url('System/ajax_tag_call')}",
            data: {name:name, _ajax:1},
            dataType: 'json',
            success: function (res) {
                if(res.code == 1){
                    //询问框
                    var confirm = layer.confirm(res.data.msg, {
                            title: false,
                            area: ['70%','80%'],
                            btn: false

                        }, function(){
                            layer.close(confirm);
                        }
                    );  
                }else{
                    showErrorMsg(res.msg);
                }
            },
            error:function(){
                showErrorAlert();
            }
        });
    });

    // 监听开关
    form.on('switch', function(data){
      var elemId = data.elem.attributes['lay-filter']['nodeValue'];
      if (data.elem.checked) {
        this.value = 1;
      } else {
        this.value = 0;
      }
      $("input[name='"+elemId+"']").val(this.value);
      setthumb(this)
    });

    //监听提交
    form.on('submit(formSubmit)', function(data){
        var load = layer_loading();
        data.field._ajax = 1;
        $.ajax({
            type : 'post',
            url : "{:url('System/thumb')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                layer.close(load); //关闭loading
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                        window.location.reload();
                    });
                }else{
                    showErrorMsg(res.msg);
                }
            },
            error: function(e){
                layer.close(load); //关闭loading
                showErrorAlert();
            }
        });
        return false;
    });
    
  });

  </script>
{include file="public/footer" /}